package com.example.flieswar.controller;
import java.util.Random;

/**
 * 敌机
 */
public class Ep  extends FlyPanel {
    int hp;
    int sp;

    public Ep() {
        //产生随机数的类
        Random rd = new Random();
        //确定敌机显示的图片
        //生成一个随机数，用来选取图片 [0,15]
        int index = rd.nextInt(15) + 1;
        System.out.println("随机数index是:" + index);
        String path = "/imgs/ep." + (index < 10 ? "0" : "") + index + ".png";
        this.img = App.getImg(path);
        //index越大的敌机，移速越快
        this.sp = 17 - index;

        //确定敌机的位置
        this.w = this.img.getWidth() / 8;
        this.h = this.img.getHeight() / 6;
        this.x = rd.nextInt(512 - this.w);
        this.y = -this.h;
        this.hp = 3;
    }
    /**
     * 让敌机移动的方法
     */
    public void move() {
        this.y += this.sp;
    }
    /**
     * 敌机是否被子弹击中
     * @param fr
     * @return
     */
    public boolean shootBy(Fire fr) {
        Boolean hit = this.x <= fr.x + fr.w && this.x >= fr.x - fr.w && this.y <= fr.y + fr.h && this.y >= fr.y - this.h;
        return hit;
    }
    /**
     * 敌机是否被英雄机撞上
     * @param fr
     * @return
     */
    public boolean hitBy(Hero hero) {
        Boolean hit = this.x <= hero.x + hero.w && this.x >= hero.x - hero.w && this.y <= hero.y + hero.h && this.y >= hero.y - this.h;
        return hit;
    }
}
